package com.swt.controller;

import com.swt.common.utils.QiNiuYunUpFileUtils;
import com.swt.common.vo.ResponseVo;
import com.swt.domain.Admin;
import com.swt.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Description
 * @Author swt
 * @Date 2022/5/17
 */
@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    public AdminService adminService;

    @PostMapping("/{count}/{size}")
    public ResponseVo pageAdmin(@PathVariable Integer count,
                                @PathVariable Integer size,
                                @RequestBody(required = false) Admin admin){
        System.out.println(admin);
        return ResponseVo.SUCCESS(adminService.pageadmin(count,size,admin));

    }
    @DeleteMapping("/{id}")
    public ResponseVo deleteAdmin(@PathVariable String id){
        return adminService.delectadmin(id)>0?ResponseVo.SUCCESS:ResponseVo.FAIL;
    }
    @GetMapping("/{id}")
    public ResponseVo selectAdminById(@PathVariable String id){
        return ResponseVo.SUCCESS(adminService.selectbyadmin(id));
    }

    /**
     * 新增用户
     * @param s
     * @return
     */
    @PostMapping
    public ResponseVo insertAdmin(@RequestBody Admin s){
        return adminService.inseradmin(s)>0?ResponseVo.SUCCESS:ResponseVo.FAIL("修改用户失败");
    }

    /**
     * 修改用户
     * @param s
     * @return
     */
    @PutMapping
    public ResponseVo updateAdmin(@RequestBody Admin s){
        return adminService.updateadmin(s)>0?ResponseVo.SUCCESS:ResponseVo.FAIL("修改用户失败");
    }

    @PostMapping("/upload")
    public ResponseVo upLoadAdminImg(MultipartFile file){
        System.out.println(file);
        return QiNiuYunUpFileUtils.getUpLoad(file);
    }
}

